using System.Collections;
using System.Xml;

namespace Mbs.CastleContainer
{
    class DefaultXmlProcessorNodeList : IXmlProcessorNodeList
    {
        private IList nodes;
        private int index = -1;

        public DefaultXmlProcessorNodeList(XmlNode node)
        {
            nodes = new ArrayList();
            nodes.Add(node);
        }

        public DefaultXmlProcessorNodeList(ArrayList nodes)
        {
            this.nodes = nodes;
        }

        public DefaultXmlProcessorNodeList(XmlNodeList nodes)
        {
            this.nodes = CloneNodeList(nodes);
        }

        /// <summary>
        /// Make a shallow copy of the nodeList.
        /// </summary>
        /// <param name="nodeList">The nodeList to be copied.</param>
        /// <returns></returns>
        protected ArrayList CloneNodeList(XmlNodeList nodeList)
        {
            ArrayList nodes = new ArrayList(nodeList.Count);

            foreach (XmlNode node in nodeList)
            {
                nodes.Add(node);
            }

            return nodes;
        }

        public XmlNode Current
        {
            get { return nodes[index] as XmlNode; }
        }

        public bool HasCurrent
        {
            get { return index < nodes.Count; }
        }

        public bool MoveNext()
        {
            return ++index < nodes.Count;
        }

        public int CurrentPosition
        {
            get { return index; }
            set { index = value; }
        }

        public int Count
        {
            get { return nodes.Count; }
        }
    }
}
